#coding:utf-8
"""
*   Coder : Dzlua
*   Email : 505544956@qq.com
*   Time  : 2017/08/18
*   Desc  : Gets a single character from standard input.
*           Does not echo to the screen.
"""

import os

#----------------------------------#
class Dzlua:
    def __init__(self):    
        self.__getch = _Getch()
    def os(self):
        return self.__getch.os()
    def getch(self):
        return self.__getch()
    def clear(self):
        osstr = self.os()
        if osstr == 'windows':
            os.system('cls')
        if osstr == 'unix':
            os.system('clear')
#----------------------------------#
# for getch
class _Getch:
    def __init__(self):
        try:
            self.impl = _GetchWindows()
        except ImportError:
            self.impl = _GetchUnix()
    def __call__(self): return self.impl()
    def os(self):
        return self.impl.os()
class _GetchUnix:
    def __init__(self):
        import tty, sys
    def __call__(self):
        import sys, tty, termios
        fd = sys.stdin.fileno()
        old_settings = termios.tcgetattr(fd)
        try:
            tty.setraw(sys.stdin.fileno())
            ch = sys.stdin.read(1)
        finally:
            termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
        return ch
    def os(self):
        return 'unix'
class _GetchWindows:
    def __init__(self):
        import msvcrt
    def __call__(self):
        import msvcrt
        return msvcrt.getch()
    def os(self):
        return 'windows'
# for getch end
#----------------------------------#
dzlua = Dzlua()
